//
//  XDGradeVideoCell.m
//  XDEducation
//
//  Created by Ethan on 2017/5/25.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XDGradeVideoCell.h"

@implementation XDGradeVideoCell
- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        [self.contentView addSubview:self.iconImageView];
        [self.contentView addSubview:self.selectClassButton];
        [self.contentView addSubview:self.gradeLabel];
        [self.contentView addSubview:self.teaLabel];
        [self.contentView addSubview:self.timeButton];
        
    }
    return self;
}


- (UIImageView *)iconImageView {
    
    if (_iconImageView == nil) {
        self.iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth/2 -15 , kScreenHeight *170/1100 )];
        self.iconImageView.backgroundColor = ThemeColor;
    }
    return _iconImageView;
}

- (UIImageView *)selectClassButton{
    if (_selectClassButton == nil){
        self.selectClassButton = [[UIImageView alloc] init];
        self.selectClassButton.frame = CGRectMake(0, 0, 45, 45);
        self.selectClassButton.center = CGPointMake(self.iconImageView.frame.size.width/2, self.iconImageView.frame.size.height/2);
        self.selectClassButton.image = [UIImage imageNamed:@"video_btn_video_default"];
    }
    return _selectClassButton;
}

- (UILabel *)gradeLabel {
    
    if (_gradeLabel == nil) {
        self.gradeLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.iconImageView.frame.origin.x, self.iconImageView.frame.origin.y + self.iconImageView.frame.size.height + 10, self.iconImageView.frame.size.width, 15)];
        self.gradeLabel.text = @"好成绩视频";
        self.gradeLabel.font = [UIFont systemFontOfSize:16.f];
        self.gradeLabel.textColor = UIColorFromRGB(0x4c4c4c);
    }
    
    return _gradeLabel;
    
}

- (UILabel *)teaLabel {
    
    if (_teaLabel == nil) {
        self.teaLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.gradeLabel.frame.origin.x, self.gradeLabel.frame.origin.y + self.gradeLabel.frame.size.height + 10, self.iconImageView.frame.size.width/2 + 10, self.gradeLabel.frame.size.height)];
        self.teaLabel.text = @"孔老师的视频";
        self.teaLabel.textColor = UIColor(150, 150, 150);
        self.teaLabel.font = [UIFont systemFontOfSize:14.f];
    }
    return _teaLabel;
    
}

- (UIButton *)timeButton {
    
    if (_timeButton == nil) {
        self.timeButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        
        self.timeButton.frame = CGRectMake(self.teaLabel.frame.origin.x + self.teaLabel.frame.size.width,self.teaLabel.frame.origin.y,self.teaLabel.frame.size.width -20,self.teaLabel.frame.size.height);
        [self.timeButton setTitle:@"1.2万" forState:(UIControlStateNormal)];
        [self.timeButton setTitleColor:UIColor(150, 150, 150) forState:(UIControlStateNormal)];
        self.timeButton.titleLabel.font = [UIFont systemFontOfSize:14.f];
        self.timeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [self.timeButton setImage:[UIImage imageNamed:@"video_icon_see_default"] forState:(UIControlStateNormal)];
    }
    
    return _timeButton;
}

- (void)setModel:(HNVideoListModel *)Model
{
    _Model = Model;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:Model.absoluteImg] placeholderImage:[self ImgForRGB:CGSizeMake(self.iconImageView.frame.size.width, self.iconImageView.frame.size.height) Color:ThemeColor]];
    self.gradeLabel.text = Model.title;
    self.teaLabel.text = Model.videoDesc;
    [self.timeButton setTitle:[Model.recomended stringValue] forState:(UIControlStateNormal)];

}

/** 颜色转图片 */
- (UIImage *)ImgForRGB:(CGSize)Size Color:(UIColor *)Color
{
    CGRect rect = CGRectMake(0, 0, Size.width, Size.height);
    UIGraphicsBeginImageContext(Size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, Color.CGColor);
    CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}



@end
